package card.rule;

import card.constant.CardConst;
import card.manager.PlatformManager;
import card.player.AbstractPlayer;

import java.util.Arrays;
import java.util.List;

/**
 * @description: 牌数规则
 * 牌数规则 发牌完成校验，平台管理
 * 1.一共54张牌
 * 2.每人17张
 * 3.底牌三张
 * @author: ly
 * @date: 2020/8/21 16:36
 */
public class CardNumRule implements Rule {

    /**
     * 检查牌数
     *
     * @param manager 管理平台
     */
    public void checkCardNum(PlatformManager manager) {
        List<String> cardContainer = manager.getCardContainer();
        if (cardContainer == null || cardContainer.size() != CardConst.TOTAL_NUM) {
            System.out.println("！！！出错了，牌数不为54张！！！");
            System.exit(1);
        }
        AbstractPlayer[] playerArr = manager.getPlayerArr();
        boolean everyNum = Arrays.stream(playerArr).anyMatch(player -> player.getCardNum() != CardConst.EVERY_NUM);
        if (everyNum) {
            System.out.println("！！！出错了，每人初始牌数应该17张！！！");
            System.exit(1);
        }
        List<String> bottom = manager.getBottom();
        if (bottom == null || bottom.size() != CardConst.BOTTOM_NUM) {
            System.out.println("！！！出错了，底牌不为3张！！！");
            System.exit(1);
        }
    }

}
